package javolution.util;

/* loaded from: classes2.dex */
public class ReentrantLock {
    private long _count;
    private Thread _owner;

    public Thread getOwner() {
        Thread thread;
        synchronized (this) {
            thread = this._owner;
        }
        return thread;
    }

    public void lock() {
        Thread currentThread = Thread.currentThread();
        synchronized (this) {
            if (currentThread == this._owner) {
                this._count++;
            } else {
                while (this._owner != null) {
                    try {
                        wait();
                    } catch (InterruptedException unused) {
                        return;
                    }
                }
                this._owner = currentThread;
                this._count = 1L;
            }
        }
    }

    public boolean tryLock() {
        synchronized (this) {
            if (this._owner == null) {
                lock();
                return true;
            }
            return false;
        }
    }

    public void unlock() {
        synchronized (this) {
            if (Thread.currentThread() != this._owner) {
                throw new IllegalMonitorStateException("Current thread does not hold this lock");
            }
            long j = this._count - 1;
            this._count = j;
            if (j == 0) {
                this._owner = null;
                notify();
            }
        }
    }
}
